package com.chinafree.business.controller;

import com.chinafree.business.model.result.Industry;
import com.chinafree.business.model.result.PositionResult;
import com.chinafree.business.model.result.ProvCityResult;
import com.chinafree.business.service.CommonService;
import com.chinafree.common.model.enumeration.ResponseCodeEnum;
import com.chinafree.common.model.response.EntityResponse;
import com.chinafree.common.model.response.ListResponse;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("common")
public class CommonController extends BaseController{

    @Autowired
    private CommonService commonService;

    @ApiOperation(value = "11" , notes = "获得城市列表")
    @PostMapping("/getCity")
    public EntityResponse<List<ProvCityResult>> getCity() {
        return commonService.getProvinceResult();
    }


    @ApiOperation(value = " 11", notes = "获得职位列表")
    @PostMapping("/getPosition")
    public EntityResponse<List<PositionResult>> getPosition() {
        return commonService.getPositionResult();
    }


    @GetMapping("/getIndustry")
    public ListResponse<Industry> getIndustry(){
        List<Industry> list =  commonService.getIndustry();
        return new ListResponse<>(ResponseCodeEnum.SUCCESS, "返回成功", list);
    }

    //上传七牛云待写
    @PostMapping("/uploadPic")
    public EntityResponse<String> uploadPic(@RequestParam("file") MultipartFile file, @RequestParam("url") String uploadDir, HttpServletRequest request) throws Exception {
        return commonService.uploadPic(file, uploadDir, request);
    }

    @GetMapping("/getUUID")
    public EntityResponse<String> getUUID(){
        UUID uuid = UUID.randomUUID();
        return  new EntityResponse<>(ResponseCodeEnum.SUCCESS,"uuid返回成功",uuid.toString());
    }

    @GetMapping("/exportPDF/token")
    public void exportPDF(@RequestParam("token") String token , HttpServletResponse response) {
        commonService.exportResume(getUserId(token),response);
    }
    

    @GetMapping("/exportPDF")
    public void exportPDFById(@RequestParam("id") Long id , HttpServletResponse response) {
        commonService.exportResume(id,response);
    }


    

}

